package com.ruoyi.student.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.student.dto.BatchUpdateStateDto;
import com.ruoyi.student.dto.InsertTrackDto;
import com.ruoyi.student.dto.RepeaterDto;
import com.ruoyi.student.dto.StudentMessageDto;
import com.ruoyi.student.vo.StudentVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.student.domain.TStudent;
import com.ruoyi.student.service.ITStudentService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 学生信息Controller
 * 
 * @author ruoyi
 * @date 2022-12-24
 */
@RestController
@RequestMapping("/studentMessage")
public class TStudentController extends BaseController
{
    @Autowired
    private ITStudentService tStudentService;

    /**
     * 查询学生信息列表
     */
    @RequiresPermissions("student:studentMessage:list")
    @GetMapping("/list")
    public TableDataInfo list(TStudent tStudent)
    {
        startPage();
        List<TStudent> list = tStudentService.selectTStudentList(tStudent);
        return getDataTable(list);
    }

    /**
     * 导出学生信息列表
     */
    @RequiresPermissions("student:studentMessage:export")
    @Log(title = "学生信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TStudent tStudent)
    {
        List<TStudent> list = tStudentService.selectTStudentList(tStudent);
        ExcelUtil<TStudent> util = new ExcelUtil<TStudent>(TStudent.class);
        util.exportExcel(response, list, "学生信息数据");
    }

    /**
     * 获取学生信息详细信息
     */
    @RequiresPermissions("student:studentMessage:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tStudentService.selectTStudentById(id));
    }

    /**
     * 新增学生信息
     */
    @RequiresPermissions("student:studentMessage:add")
    @Log(title = "学生信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StudentMessageDto studentMessageDto)
    {
        System.out.println(studentMessageDto);
        return toAjax(tStudentService.insertTStudent(studentMessageDto));
    }

    /**
     * 修改学生信息
     */
    @RequiresPermissions("student:studentMessage:edit")
    @Log(title = "学生信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TStudent tStudent)
    {
        return toAjax(tStudentService.updateTStudent(tStudent));
    }

    /**
     * 删除学生信息
     */
    @RequiresPermissions("student:studentMessage:remove")
    @Log(title = "学生信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tStudentService.deleteTStudentByIds(ids));
    }

    /**
     *批量修改学生状态
     */
//    @RequiresPermissions("student:studentMessage:edit")
//    @Log(title = "学生信息", businessType = BusinessType.UPDATE)
    @PutMapping("/batchStudentMessage")
    public AjaxResult batchEdit(@RequestBody BatchUpdateStateDto batchUpdateStateDto)
    {

        return toAjax(tStudentService.batchEdit(batchUpdateStateDto));
    }
    /**
    * 转班留级
    */
    @PostMapping("/updateStateClass")
    public AjaxResult repeater(@RequestBody RepeaterDto repeaterDto)
    {
        return toAjax(tStudentService.repeater(repeaterDto));
    }


    /**
     *
     * 添加跟踪
     */
    @PostMapping("/insertTrack")
    public AjaxResult insertTrack(@RequestBody InsertTrackDto insertTrackDto)
    {
        return toAjax(tStudentService.insertTrack(insertTrackDto).isSuccess());
    }

    /**
     * 根据班级id查询学生
     * */
    @GetMapping("/findStudentNameByClassId")
    public List<StudentVo> findStudentNameByClassId(){
        return tStudentService.findStudentNameByClassId();
    }
    /**
     * 根据班级id查询学生
     * */
    @GetMapping("/findStudentName/{classesId}")
    public List<TStudent> findStudentName(@PathVariable("classesId") Long classesId){
        return tStudentService.findStudentName(classesId);
    }

    /**
     * 根据名字查询信息
     * @param name
     * @return
     */
    @GetMapping("/getStudent/{name}")
    public AjaxResult findStudentByName(@PathVariable("name") String name){
        return AjaxResult.success(tStudentService.findStudentByName(name));
    }

}
